"""
特殊访客模型
创建时间：2025-09-12
作者：开发团队
目的：定义特殊访客数据模型
"""

from sqlalchemy import Column, Integer, String, DateTime, Date, Text, ForeignKey
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from ..core.database import Base


class SpecialVisitor(Base):
    """特殊访客模型"""
    
    __tablename__ = "special_visitors"
    
    # 基础字段
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    name = Column(String(100), nullable=False)
    phone = Column(String(20), nullable=False, unique=True, index=True)
    id_card = Column(String(20), unique=True, index=True)
    type = Column(String(20), nullable=False, index=True)  # VIP, 纠纷, 其他
    valid_until = Column(Date, nullable=False, index=True)
    remarks = Column(Text)
    campus_id = Column(Integer, ForeignKey("campuses.id"))
    created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), nullable=False)
    updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc), nullable=False)
    
    # 关系
    campus = relationship("Campus", back_populates="special_visitors")
    
    def __repr__(self):
        return f"<SpecialVisitor(id={self.id}, name='{self.name}', type='{self.type}')>"